package com.sunxueqi.project.system.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.sunxueqi.framework.web.controller.BaseController;
import com.sunxueqi.framework.web.vo.ResponseData;
import com.sunxueqi.project.system.service.ICarouselService;
import com.sunxueqi.project.system.vo.Carousel;

import cn.hutool.core.util.StrUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags="首页轮播图")
@RestController
@RequestMapping("/system/carousel")
public class CarouselController extends BaseController{
	@Autowired
	private ICarouselService carouselService;
	
	/**
	 * 获取所有的轮播图
	 * @param carousel
	 * @return
	 */
	@ApiOperation("获取轮播图列表")
	@GetMapping("/list")
	public ResponseData list(Carousel carousel) {
		startPage();
		List<Carousel> list = carouselService.selectCarouselList(carousel);
		return ResponseData.successTableData(list);
	}
	
	/**
	 * 新增轮播图
	 * @param Carousel
	 * @return
	 */
	@ApiOperation("新增轮播图")
	@PostMapping
	public ResponseData add(@RequestBody Carousel Carousel) {
		return super.getResponseDataRow(carouselService.add(Carousel));
	}
	
	/**
	 * 删除轮播图
	 * @param ids
	 * @return
	 */
	@ApiOperation("删除轮播图")
	@DeleteMapping("/{ids}")
	public ResponseData delete(@PathVariable String ids) {
		String [] idArray = StrUtil.split(ids, ",");
		return super.getResponseDataRow(carouselService.deleteCarouselByIds(idArray));
	}
	
	/**
	 * 修改轮播图
	 * @param carousel
	 * @return
	 */
	@ApiOperation("修改轮播图")
	@PutMapping
	public ResponseData update(@RequestBody Carousel carousel) {
		return super.getResponseDataRow(carouselService.updateCarousel(carousel));
	}
	
	/**
	 * 修改轮播图显示状态
	 * @param Carousel
	 * @return
	 */
	@ApiOperation("修改轮播图状态")
	@PutMapping("/changeStatus")
	public ResponseData changeStatus(@RequestBody Carousel carousel) {
		return getResponseDataRow(carouselService.changeStatus(carousel));
	}
	/**
	 * 修改点击轮播图是否打开新窗口
	 * @param Carousel
	 * @return
	 */
	@ApiOperation("点击轮播图是否打开新窗口")
	@PutMapping("/changeTarget")
	public ResponseData changeTarget(@RequestBody Carousel carousel) {
		return getResponseDataRow(carouselService.changeTarget(carousel));
	}
	
	
}
